# --------------------------------------------------
# --------------------- MySQL ----------------------
# --------------------------------------------------

. ${CONF_DIR}/mysql
. ${CONF_DIR}/roundcube

# MySQL root password.
while : ; do
    ${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Password for MySQL administrator: root" \
    --insecure --passwordbox "\
Please specify password for MySQL administrator: root

Warnning:

    * EMPTY password is *NOT* permit.
" 20 76 2>/tmp/mysql_rootpw

    MYSQL_ROOTPW="$(cat /tmp/mysql_rootpw)"
    [ X"${MYSQL_ROOTPW}" != X"" ] && break
done

echo "MYSQL_ROOTPW='${MYSQL_ROOTPW}'" >>${CONFIG_FILE}
rm -f /tmp/mysql_rootpw

# MySQL bind/admin user passwd.
while : ; do
    ${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Password for virtual hosts bind user and admin user" \
    --insecure --passwordbox "\
Please specify password for virtual hosts bind user and admin user:

    * bind user: ${MYSQL_BIND_USER}
    * admin user: ${MYSQL_ADMIN_USER}

Warnning:

    * EMPTY password in *NOT* permit.

" 20 76 2>/tmp/mysql_user_and_passwd

    MYSQL_BIND_PW="$(cat /tmp/mysql_user_and_passwd)"
    MYSQL_ADMIN_PW="${MYSQL_BIND_PW}"

    [ X"${MYSQL_BIND_PW}" != X"" ] && break
done

echo "MYSQL_BIND_USER='${MYSQL_BIND_USER}'" >> ${CONFIG_FILE}
echo "MYSQL_ADMIN_USER='${MYSQL_ADMIN_USER}'" >> ${CONFIG_FILE}
echo "MYSQL_BIND_PW='${MYSQL_BIND_PW}'" >> ${CONFIG_FILE}
echo "MYSQL_ADMIN_PW='${MYSQL_BIND_PW}'" >> ${CONFIG_FILE}
rm -f /tmp/mysql_user_and_passwd

# INFO
${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "MySQL bind and manage info" \
    --msgbox "\
Important Note:

    * Bind info for all MySQL operations:

        * MYSQL server:     ${MYSQL_SERVER}
        * MYSQL port:       ${MYSQL_PORT}
        * Bind user:        ${MYSQL_BIND_USER}
        * Bind password:    ${MYSQL_BIND_PW}

    * vmail database can be managed by:

        * MYSQL user:       ${MYSQL_ADMIN_USER}
        * MYSQL password:   ${MYSQL_ADMIN_PW}
" 20 76

# Password for roundcubemail database.
while : ; do
    ${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "User & Password for Roundcubemail database" \
    --insecure --passwordbox "\
Please specify password for Roundcubemail database:

    * Database Name: ${RCD_DB}
    * Database User: ${RCD_DB_USER}

Warnning:

    * EMPTY password in *NOT* permit.

" 20 76 2>/tmp/rcd_db_passwd

    RCD_DB_PASSWD="$(cat /tmp/rcd_db_passwd)"
    [ X"${RCD_DB_PASSWD}" != X"" ] && break
done

echo "RCD_DB_PASSWD='${RCD_DB_PASSWD}'" >> ${CONFIG_FILE}
rm -f /tmp/rcd_db_passwd

# Username of PostfixAdmin site admin.
${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Username of PostfixAdmin site admin" \
    --inputbox "\
Please specify the username of PostfixAdmin site admin.

EXAMPLE:

    * michaelbibby@gmail.com

" 20 76 2>/tmp/site_admin_name

SITE_ADMIN_NAME="$(cat /tmp/site_admin_name)"
echo "SITE_ADMIN_NAME='${SITE_ADMIN_NAME}'" >>${CONFIG_FILE}
rm -f /tmp/site_admin_name

# Password for PostfixAdmin site admin.
while : ; do
    ${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Password of PostfixAdmin site admin" \
    --insecure --passwordbox "\
Please specify the password of site admin in PostfixAdmin:

Warnning:

    * EMPTY password in *NOT* permit.

" 20 76 2>/tmp/site_admin_passwd

    SITE_ADMIN_PASSWD="$(cat /tmp/site_admin_passwd)"
    [ X"${SITE_ADMIN_PASSWD}" != X"" ] && break
done

echo "SITE_ADMIN_PASSWD='${SITE_ADMIN_PASSWD}'" >> ${CONFIG_FILE}
rm -f /tmp/site_admin_passwd

# First domain name.
${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Your first virtual domain" \
    --inputbox "\
Please specify the name of your first virtual domain.

EXAMPLES:

    * openbsdonly.org
    * example.com
    * hello.net

" 20 76 2>/tmp/first_domain

FIRST_DOMAIN="$(cat /tmp/first_domain)"
echo "FIRST_DOMAIN='${FIRST_DOMAIN}'" >> ${CONFIG_FILE}
rm -f /tmp/first_domain

#FIRST_DOMAIN_ADMIN_NAME
${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Specify administrator' name of your virtual domain" \
    --inputbox "\
Please specify administrator' name of your virtual domain.

EXAMPLE:

    * postmaster

    " 20 76 "postmaster" 2>/tmp/first_domain_admin_name

FIRST_DOMAIN_ADMIN_NAME="$(cat /tmp/first_domain_admin_name)"
echo "FIRST_DOMAIN_ADMIN_NAME='${FIRST_DOMAIN_ADMIN_NAME}'" >>${CONFIG_FILE}
rm -f /tmp/first_domain_admin_name

# FIRST_DOMAIN_ADMIN_PASSWD
while : ; do
    ${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Password for the administrator of your domain" \
    --insecure --passwordbox "\
Please specify password for the administrator user:

    * ${FIRST_DOMAIN_ADMIN_NAME}

Warnning:

    * EMPTY password is *NOT* permit.

" 20 76 2>/tmp/first_domain_admin_passwd

    FIRST_DOMAIN_ADMIN_PASSWD="$(cat /tmp/first_domain_admin_passwd)"

    [ X"${FIRST_DOMAIN_ADMIN_PASSWD}" != X"" ] && break
done

echo "FIRST_DOMAIN_ADMIN_PASSWD='${FIRST_DOMAIN_ADMIN_PASSWD}'" >> ${CONFIG_FILE}
rm -f /tmp/first_domain_admin_passwd

#FIRST_USER
FIRST_USER='www'
${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Add a user for your domain" \
    --inputbox "\
Please specify the username of your first domain: ${FIRST_DOMAIN}.

EXAMPLE:

    * ${FIRST_USER}

" 20 76 "${FIRST_USER}" 2>/tmp/first_user

FIRST_USER="$(cat /tmp/first_user)"
echo "FIRST_USER='${FIRST_USER}'" >>${CONFIG_FILE}
rm -f /tmp/first_user

# FIRST_USER_PASSWD
while : ; do
    ${DIALOG} --backtitle "${DIALOG_BACKTITLE}" \
    --title "Password for your first user" \
    --insecure --passwordbox "\
Please specify password for your first user:

    * ${FIRST_USER}@${FIRST_DOMAIN}

Warnning:

    * EMPTY password is *NOT* permit.

" 20 76 2>/tmp/first_user_passwd

    FIRST_USER_PASSWD="$(cat /tmp/first_user_passwd)"
    [ X"${FIRST_USER_PASSWD}" != X"" ] && break
done

echo "FIRST_USER_PASSWD='${FIRST_USER_PASSWD}'" >>${CONFIG_FILE}
rm -f /tmp/first_user_passwd
